package com.droolsBoot.service;

import org.kie.api.KieBase;
import org.kie.api.io.ResourceType;
import org.kie.internal.utils.KieHelper;

/**
 * 该类用来初始化规则库
 *
 * KieHelper 是Kie自己封装的工具类
 * 简化了规则的构建，可快速生成规则容器、规则库等
 */
public class NewKieBase {
    //将业务规则写到规则库中
    public static KieBase rulekieBase(String rule) {
        //通过 KieHelper 创建一个规则库
        KieHelper helper = new KieHelper();
        try {
            helper.addContent(rule, ResourceType.DRL);
            return helper.build();
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException("规则初始化失败");
        }
    }
}
